module planegame{

    export class SanBullet extends Bullet {

        private bulletOffset;
        private bulletFlyTime;

        private bulletOffsetFinish;

        public constructor(resName:string) {
            super();
            this.bulletNum = 3;
            let res = RES.getRes("description_json");
            this.bulletOffset = res.bulletOffset.san;
            this.bulletFlyTime = res.bulletFlyTime.san;
            this.bulletOffsetFinish = res.bulletOffsetFinish.san;
            this.resName = resName;
        }

        public fire() {
            let plane:Plane = <Plane>this.parent;
            let game:Game = <Game>plane.parent;
            for(let i:number = 0;i<this.bulletNum;i++) {
                let v = this.getBullet(this.resName);
                
                v.x = plane.x + this.bulletOffset[i].x;
                v.y = plane.y - v.height/2 + this.bulletOffset[i].y;

                game.addChild(v);
                plane.bulletArray.push(v);

                egret.Tween.get(v).to({x:v.x+this.bulletOffsetFinish[i].x, y:v.y+this.bulletOffsetFinish[i].y}, this.bulletFlyTime).call(function() {
                    let index = plane.bulletArray.indexOf(v);
                    if(index != -1) {
                        plane.bulletArray.splice(index, 1);
                    }
                    if(game.contains(v)) {
                        game.removeChild(v);
                    }
                }, this);
            }
           
        }
    }
}